package com.pubinfo.passbook.api.controller.auth;

import com.pubinfo.passbook.common.entity.TSystemMenu;
import com.pubinfo.passbook.common.model.dto.system.MenuParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TSystemMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("menu/manager")
@Api(tags = "菜单管理")
@Slf4j
public class TMenuController {
  
  @Autowired
  private TSystemMenuService menuService;
  
  @PostMapping("select")
  @ApiModelProperty("查询菜单列表")
  public JsonResult<MyPage<TSystemMenu>> selectSystemMenu(@RequestBody MenuParam param) {
    return JsonResult.success(new MyPage(menuService.selectSystemMenu(param)));
  }
  
  @PostMapping("save")
  @ApiModelProperty("新增菜单")
  public JsonResult<String> saveSystemMenu(@Valid @RequestBody TSystemMenu menu) {
    return menuService.saveSystemMenu(menu);
  }
  
  @PostMapping("remove")
  @ApiModelProperty("删除菜单")
  public JsonResult<String> removeSystemMenu(Integer menuId) {
    return menuService.removeSystemMenu(menuId);
  }
  
  @PostMapping("update")
  @ApiModelProperty("修改菜单")
  public JsonResult<String> updateSystemMenu(@Valid @RequestBody TSystemMenu menu) {
    return menuService.updateSystemMenu(menu);
  }
  
  @PostMapping("selectMenuTree")
  @ApiModelProperty("获取菜单树")
  public JsonResult<List<TSystemMenu>> selectMenuTree(Integer menuId) {
    return JsonResult.success(menuService.selectMenuTree(menuId));
  }
}
